package com.glela.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.glela.goods.model.request.ActivitiesGoodsRequest;
import com.glela.goods.model.vo.goods.GoodsAndTitleVo;
import com.glela.goods.service.ActivityService;
import com.glela.platform.constant.ErrorEnum;
import com.glela.platform.model.response.ResponseBaseModel;
import com.glela.platform.model.response.ResponseResultModel;
import com.glela.platform.util.ParameterUtils;

/** 
* @author  wuyue
* @date 创建时间：2017年10月22日 下午2:17:41 
* @version 1.0 
* @parameter  
* @since  
* @return  
*/
@Controller
@RequestMapping(value = "/activeProducts")
public class ActivitiesGoodsController {
	private static Logger logger = LoggerFactory.getLogger(ActivitiesGoodsController.class);
	
	@Autowired
	private ActivityService activityService;
	
	/**
	 * 
	* **********************************************
	* @Title: activeProductsList 
	* @Description: 
	* @param @param request
	* @param @return 
	* @return ResponseEntity<?>
	* @throws	
	* @author wy	
	* @date 2017年10月20日 下午6:13:11 
	* **********************************************
	 */
	@RequestMapping(value = "/activeProductsList", method = RequestMethod.POST, consumes = "application/json")
		public ResponseEntity<?> activeProductsList(@RequestBody ActivitiesGoodsRequest request) {
		try {
			//缺少必传参数
			long marketingActivitiesId = request.getMarketingActivitiesId();
			int pageNum = request.getPage();
			
			int StartIndex = request.getStartIndex();
			int pageSize = request.getPageSize();
			Long userId = request.getUserId();
			if (ParameterUtils.validParams(marketingActivitiesId)&&ParameterUtils.validParams(userId)&&ParameterUtils.validParams(pageSize)&&ParameterUtils.validParams(pageNum)) {
				return new ResponseEntity<>(new ResponseBaseModel(ErrorEnum.C20102), HttpStatus.OK);
			}
			
			GoodsAndTitleVo vo = this.activityService.selectActiveProductsListById(marketingActivitiesId,userId,StartIndex,pageSize,pageNum);
			if(vo == null){
				return new ResponseEntity<>(new ResponseBaseModel(ErrorEnum.C20400), HttpStatus.OK);
			}
			return new ResponseEntity<>(new ResponseResultModel<>(vo), HttpStatus.OK);
		} catch (Exception e) {
			logger.error("活动商品列表显示异常", e);
			return new ResponseEntity<>(new ResponseBaseModel(ErrorEnum.C20000), HttpStatus.OK);
		}
	}

}
